package com.takeaway.ui.fragment

import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.takeaway.R
import com.takeaway.ui.activity.LoginActivity
import com.takeaway.utils.TakeOutApplication
import kotlinx.android.synthetic.main.fragment_mine.*
import org.jetbrains.anko.support.v4.startActivity

class MineFragment : Fragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = View.inflate(activity, R.layout.fragment_mine, null)
        Log.e("MineFragment", "初始化")
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initListener()
    }

    private fun initListener() {
        login.setOnClickListener {
            startActivity<LoginActivity>()
        }
    }


    override fun onStart() {
        super.onStart()
        val user = TakeOutApplication.user
        if (user.userId == -1) { // 未登录
            login.visibility = View.VISIBLE
            ll_userinfo.visibility = View.GONE
//            username.visibility = View.GONE
//            phone.visibility = View.GONE
        } else {
            login.visibility = View.GONE
            ll_userinfo.visibility = View.VISIBLE
//            username.visibility = View.VISIBLE
//            phone.visibility = View.VISIBLE
            username.text = user.username
            phone.text = user.phone
        }
    }

}